#!/bin/bash
#
# Copyright (C)2007 Giulio Bai
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.



echo "Please enter the host IP address:" 
read ip

echo "Check if the host is online? [yes/no]" 
read answer1 

if [ $answer1 = "yes" ]; then
	# Just pings the host displaying the result
	ping $ip -c 2
else
	echo "Skipping..."
fi
echo ""

echo "Scan host (nmap required)? [yes/no]"
read answer2
if [ $answer2 = "yes" ]; then
	echo "Checking if nmap is installed... "

	# Uses which to check the path of the installation 8if installed)
	# Redirects the standard output ('>') to the virtual path /dev/null and
	# redirects the standard error (file id '2') to the standard output ('1')
	# path, so in /dev/null
	#
	# This is to avoid any (error) message is displayed since the user
	# doesn't want to see anything
	which nmap > /dev/null 2>&1

	# Nmap not installed
	#
	# TODO add the installation process (eg by using apt-get for Debian or wget)
	if [ $? -ne 0 ]; then
		echo "nmap not found in the system. Run your packet manager to install it."
		echo ""
		echo "QUITTING"
		exit;
	else
		echo ""
		# Run nmap to scan the host
		nmap -sV -O $ip 
	fi
else
	echo "QUITTING"
	exit;
fi
